package com.fw.service.sample.impl;

import org.springframework.beans.factory.annotation.Autowired;

import com.fw.service.persistence.SampleService;
import com.fw.service.persistence.dto.Sample;
import com.fw.service.sample.TestService;

public class TestServiceImpl implements TestService {

    // private static Logger logger = Logger.getLogger(TestServiceImpl.class);

    @Autowired
    SampleService sampleService;

    private static int callTest = 0;
    private static int callAddTest = 0;

    public String test(String text) {
	callTest++;
	System.out.println("==============================> callTest " + callTest + ", text = " + text);
	return "Hello " + text;
    }

    public Boolean addText(String text) {
	try {
	    callAddTest++;
	    System.out.println("==============================> callAddTest " + callAddTest);
	    // logger.info("Add Text to Sample DB 'Hello " + text + "'");
	    Sample sample = new Sample();
	    sample.setText("Hello " + text);
	    sampleService.saveSample(sample);
	    if (sample.getId() != null) {
		return true;
	    }
	    return false;
	} catch (Exception e) {
	    e.printStackTrace();
	    // logger.error("Error " + e.getMessage());
	}
	return false;
    }

}
